@extends('layouts.admin')

@section('nav')
    @include('admin/event/nav')
@endsection

@section('cont')
    <form class="form-horizontal" id="sample-form" method="post"
          action="{{url('/admin/materials/add',['id'=>$event->id])}}" enctype="multipart/form-data">
        {{ csrf_field() }}
        <input type="hidden" name="class_id" value="{{$event->class_id}}">
        <input type="hidden" name="week_id" value="{{$event->week_id}}">
        <input type="hidden" name="term_id" value="{{$event->term_id}}">
        <div class="row">
            <div class="col-xs-12">
                <div class="form-group">
                    <label for="show_order" class="col-xs-12 col-sm-2 control-label no-padding-right">显示序号：</label>

                    <div class="col-xs-12 col-sm-5">
                        <span class="block input-icon input-icon-right">
                            <input type="number" name="show_order" value="{{ $show_order }}" required id="show_order"
                                   class="width-100">
                        </span>
                    </div>
                    <div class="help-block col-xs-12 col-sm-reset inline red">
                        *(必填)
                    </div>
                </div>
                <div class="form-group">
                    <label for="show_order" class="col-xs-12 col-sm-2 control-label no-padding-right">负责人：</label>

                    <div class="col-xs-12 col-sm-5 help-block">
                        <span class="block input-icon input-icon-right">
                            {{$event->user_name}}
                        </span>
                    </div>
                </div>
                <div class="form-group">
                    <label for="show_order" class="col-xs-12 col-sm-2 control-label no-padding-right">班级：</label>

                    <div class="col-xs-12 col-sm-5 help-block">
                        <span class="block input-icon input-icon-right">
                            {{$event->classname}}
                        </span>
                    </div>
                </div>
                <div class="form-group">
                    <label for="show_order" class="col-xs-12 col-sm-2 control-label no-padding-right">周次：</label>

                    <div class="col-xs-12 col-sm-5 help-block">
                        <span class="block input-icon input-icon-right">
                            {{$event->weekname}}
                        </span>
                    </div>
                </div>
                <div class="form-group">
                    <label for="show_order" class="col-xs-12 col-sm-2 control-label no-padding-right">当前大事纪：</label>

                    <div class="col-xs-12 col-sm-5 help-block">
                        <span class="block input-icon input-icon-right">
                            {{$event->title}}
                        </span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 佐证材料: </label>
                    <div class="col-sm-8">
                        <div class="row">
                            <div class="col-xs-12">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn layui-btn-normal" id="testList">
                                        选择多文件
                                    </button>
                                    <button type="button" class="layui-btn" id="testListAction">开始上传</button>
                                    <div style="color: red">备注：1.可同时选择多个文件，请务必在选择文件后点击“开始上传”按钮！&nbsp;2.文件格式支持图片、word、excel、pdf！
                                    </div>
                                    <div class="layui-upload-list">
                                        <table class="layui-table">
                                            <thead>
                                            <th>文件名</th>
                                            <th>大小</th>
                                            <th>状态</th>
                                            <th>操作</th>
                                            </thead>
                                            <tr>
                                            </tr>
                                            <tbody id="demoList"></tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label for="show_order" class="col-xs-12 col-sm-2 control-label no-padding-right">添加人：</label>

                    <div class="col-xs-12 col-sm-5 help-block">
                            <span class="help-block block input-icon input-icon-right">
                                {{session()->get('user')->username}}
                            </span>
                    </div>
                </div>
                <div class="clearfix form-actions" style="background-color: #fff;border: none;">
                    <div class="col-md-offset-3 col-md-8">
                        <button onclick="return tijiao();" class="btn btn-info" type="submit">
                            <i class="ace-icon fa fa-check bigger-110"></i>
                            提交
                        </button>

                        &nbsp; &nbsp; &nbsp;
                        <button class="btn" type="reset">
                            <i class="ace-icon fa fa-undo bigger-110"></i>
                            重置
                        </button>
                    </div>
                </div>
            </div>
        </div>
        </div>
    </form>
@endsection

@section('js')
    <script>
        layui.use(['form', 'layer'], function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;

            //自定义验证规则
            form.verify({
                nikename: function (value) {
                    if (value.length < 5) {
                        return '昵称至少得5个字符啊';
                    }
                },
                pass: [/(.+){6,12}$/, '密码必须6到12位'],
                repass: function (value) {
                    if ($('#L_pass').val() != $('#L_repass').val()) {
                        return '两次密码不一致';
                    }
                }
            });
        });
        layui.use('upload', function () {
            var $ = layui.jquery,
                upload = layui.upload;
            var demoListView = $('#demoList'),
                uploadListIns = upload.render({
                    elem: '#testList',
                    url: '/admin/materials/upload' //改成您自己的上传接口
                    ,
                    accept: 'file',
                    multiple: true,
                    field: 'file',
                    dataType: "json",
                    auto: false,
                    bindAction: '#testListAction',
                    choose: function (obj) {
                        var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                        //读取本地文件
                        obj.preview(function (index, file, result) {
                            var tr = $(['<tr id="upload-' + index + '">', '<td>' + file.name + '</td>', '<td>' + (file.size / 1024).toFixed(1) + 'kb</td>', '<td>等待上传</td>', '<td>', '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>', '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>', '</td>', '</tr>'].join(''));

                            //单个重传
                            tr.find('.demo-reload').on('click', function () {
                                obj.upload(index, file);
                            });

                            //删除
                            tr.find('.demo-delete').on('click', function () {
                                delete files[index]; //删除对应的文件
                                tr.remove();
                                uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                            });

                            demoListView.append(tr);
                        });
                    },
                    done: function (res, index, upload) {
                        console.log(res.status);
                        if (res.status) { //上传成功
                            var tr = demoListView.find('tr#upload-' + index),
                                tds = tr.children();
                            tds.eq(2).html('<span style="color: #5FB878;"><input type="hidden" name="file[]" value="' + res.msg + '"/>上传成功</span>');
                            tds.eq(3).html(''); //清空操作
                            return delete this.files[index]; //删除文件队列已经上传成功的文件
                        }
                        this.error(index, upload);
                    },
                    error: function (index, upload) {
                        var tr = demoListView.find('tr#upload-' + index),
                            tds = tr.children();
                        tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
                        tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
                    }
                });
        });
    </script>
@endsection
